<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>网点管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	#parse('/headFiles.html')
  	<style type="text/css">.layui-word-aux{color:red !important;}</style>
</head>
<body>
<div class="layui-form" style="position:absolute;top:15px;left:15px;z-index:10;">
	<input type="hidden" name="id" value="$!{id}"/>
	<input type="hidden" name="longitude" value="$!{longitude}"/>
	<input type="hidden" name="latitude" value="$!{latitude}"/>
	<div class="layui-form-item">
		<div class="layui-input-inline"><input type="text" name="address" placeholder="请输入地址" class="layui-input" value="$!{address}"></div>
		<div class="layui-input-inline"><button type="button" class="layui-btn" id="btnSearch">查询</button></div>
		
		<div class="layui-form-mid layui-word-aux" id="txtLongitude">经度：$!{longitude}</div>
		<div class="layui-form-mid layui-word-aux" id="txtLatitude">纬度：$!{latitude}</div>
	</div>
	<div class="layui-form-item layui-hide">
     	<input type="button" lay-submit lay-filter="LAY-form-submit" id="LAY-form-submit" value="$!{i18n.get('ok')}">
     	<input type="button" lay-submit lay-filter="LAY-form-update" id="LAY-form-update" value="$!{i18n.get('update')}">
   	</div>
</div>
<div id="mapPanel" style="position:absolute;top:0;bottom:0;left:0;right:0;z-index:5;"></div>
#parse('/footFiles.html')
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=a25f123c4ea1dda838295a988829f9fe"></script> 
<script type="text/javascript">
layui.config({
  base: '$!{webRoot}/layuiadmin/'
}).extend({
  index: 'lib/index'
}).use(['index', 'form'], function(){
  var $ = layui.$,form = layui.form;
  
  var longitude = $('input[name="longitude"]').val();
  var latitude = $('input[name="latitude"]').val();
  var map,marker;
  
  if(longitude && latitude){
	  map = new AMap.Map('mapPanel', {center:[longitude,latitude],zoom:18});
  }else{
	  map = new AMap.Map('mapPanel', {center:[116.39,39.9],zoom:18});
  }
  
  AMap.service(["AMap.PlaceSearch"], function() {
      //构造地点查询类
      var placeSearch = new AMap.PlaceSearch({ 
          pageSize: 5, // 单页显示结果条数
          pageIndex: 1, // 页码
          city:'$!{city}',
          citylimit:true,
	      zoom:18,
          map: map, // 展现结果的地图实例
          autoFitView: true // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
      });
      
      $('#btnSearch').click(function(){
    	  var address = $('input[name="address"]').val();
    	  placeSearch.search(address);
      });
  });
  
  var icon = new AMap.Icon({
    size: new AMap.Size(40, 50),    // 图标尺寸
    image: '$!{webRoot}/layuiadmin/style/res/2.png',  // Icon的图像
    imageSize: new AMap.Size(40, 50)
  });
  
  if(longitude && latitude){
	//返回定位信息
	marker = new AMap.Marker({
	    position: new AMap.LngLat(longitude, latitude),
	    icon: icon
	});
	map.add(marker);
  }
  
  map.on('click', function(e) {
	  $('input[name="longitude"]').val(e.lnglat.getLng());
	  $('input[name="latitude"]').val(e.lnglat.getLat());
	  $('#txtLongitude').html('经度:'+e.lnglat.getLng());
	  $('#txtLatitude').html('纬度:'+e.lnglat.getLat());
	  
	  if(marker){
		  marker.setPosition(e.lnglat);
	  }else{
		  marker = new AMap.Marker({
		    position: e.lnglat,
		    icon: icon
		  });
		  map.add(marker);
	  }
  });
});
</script>
</body>
</html>